package com.woniuxy.yoga.progress.web.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.yoga.commons.core.model.Result;
import com.woniuxy.yoga.commons.web.log.YogaLog;
import com.woniuxy.yoga.progress.dao.model.Pricard;
import com.woniuxy.yoga.progress.model.form.CreatePriCardForm;
import com.woniuxy.yoga.progress.model.form.GetUnfinishPriByIdForm;
import com.woniuxy.yoga.progress.model.param.CreatePriCardParam;
import com.woniuxy.yoga.progress.service.PricardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 私教课流程表 前端控制器
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@RestController
@RequestMapping("/pricard")
@Api(tags = "私教课进度管理")
@Validated
public class PricardController {

    @Autowired
    private PricardService pricardService;

    /**
     * 创建私教课进度表
     * @param form 创建私教课进度表参数
     * @return String
     */
    @PostMapping("/createPriCard")
    @ApiOperation("创建私教课进度表")
    @YogaLog("创建私教课进度表")
    public Result<?> createPriCard(@RequestBody @Valid CreatePriCardForm form){
        pricardService.createPriCard(BeanUtil.toBean(form, CreatePriCardParam.class));
        return Result.getResult().setMessage("创建私教课进度表成功");
    }

    /**
     * 私教进度次数加一
     * @param pricardId 私教id
     * @return string
     */
    @GetMapping("/addPriCardCount/{pricardId}")
    @ApiOperation("私教进度次数加一")
    @YogaLog("私教进度次数加一")
    public Result<String> addPriCardCount(@PathVariable("pricardId") @Valid @NotNull Integer pricardId) throws Exception {
        pricardService.addSubCardCount(pricardId);
        return Result.getResult(String.class).setMessage("操作成功");
    }

    /**
     * 完成私教卡
     * @param pricardId 私教卡id
     * @return String
     */
    @GetMapping("/finishPricard/{pricardId}")
    @ApiOperation("完成私教卡")
    @YogaLog("完成私教卡")
    public Result<String> finishPricard(@PathVariable("pricardId") @Valid @NotNull Integer pricardId){
        pricardService.finishPricard(pricardId);
        return Result.getResult(String.class).setMessage("操作成功");
    }

    /**
     * 查询未完成私教卡
     * @param userId userId
     * @return Pricard
     */
    @GetMapping("/getUnfinishPri/{userId}")
    @ApiOperation("查询未完成私教卡")
    @YogaLog("查询未完成私教卡")
    public Result<Pricard> getUnfinishPri(@PathVariable("userId") @Valid @NotNull Integer userId){
        Pricard pricard = pricardService.getUnfinishPri(userId);
        return Result.getResult(Pricard.class).setMessage("查询成功").setData(pricard);
    }

    /**
     * 查询未完成私教卡
     * @param form form
     * @return Pricard
     */
    @PostMapping("/getUnfinishPriById")
    @ApiOperation("通过教练id用户id查询未完成私教卡")
    @YogaLog("通过教练id用户id查询未完成私教卡")
    public Result<Integer> getUnfinishPriById(@RequestBody GetUnfinishPriByIdForm form) {
        Integer pricardId = pricardService.getUnfinishPriById(form);
        return Result.getResult(Integer.class).setMessage("查询成功").setData(pricardId);
    }

}

